<?php

/**
 * This is the model class for table "sucursales".
 *
 * The followings are the available columns in table 'sucursales':
 * @property integer $sucursales_id
 * @property string $descripcion
 * @property string $domicilio
 * @property integer $localidades_id
 * @property integer $provincias_id
 * @property string $telefono
 *
 * The followings are the available model relations:
 * @property Alquiler[] $alquilers
 * @property Provincias $provincias
 * @property Localidades $localidades
 * @property Canchas[] $canchases
 * @property Empleados[] $empleadoses
 */
class Sucursales extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Sucursales the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sucursales';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('descripcion, domicilio, localidades_id, provincias_id, telefono', 'required'),
			array('localidades_id, provincias_id', 'numerical', 'integerOnly'=>true),
			array('descripcion', 'length', 'max'=>100),
			array('domicilio', 'length', 'max'=>150),
			array('telefono', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('sucursales_id, descripcion, domicilio, localidades_id, provincias_id, telefono', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'alquilers' => array(self::HAS_MANY, 'Alquiler', 'sucursales_id'),
			'provincias' => array(self::BELONGS_TO, 'Provincias', 'provincias_id'),
			'localidades' => array(self::BELONGS_TO, 'Localidades', 'localidades_id'),
			'canchases' => array(self::HAS_MANY, 'Canchas', 'sucursales_id'),
			'empleadoses' => array(self::HAS_MANY, 'Empleados', 'sucursales_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'sucursales_id' => 'Sucursales',
			'descripcion' => 'Descripcion',
			'domicilio' => 'Domicilio',
			'localidades_id' => 'Localidades',
			'provincias_id' => 'Provincias',
			'telefono' => 'Telefono',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('sucursales_id',$this->sucursales_id);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('domicilio',$this->domicilio,true);
		$criteria->compare('localidades_id',$this->localidades_id);
		$criteria->compare('provincias_id',$this->provincias_id);
		$criteria->compare('telefono',$this->telefono,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}